/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.ui;

import ac.ui.controls.PCLCheckBox;
import ac.ui.controls.PCLCode;
import ac.ui.controls.PCLPanel;
import ac.ui.controls.PCLTree;
import java.awt.Component;
import java.io.File;
import java.text.SimpleDateFormat;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;

import org.jdesktop.swingx.JXDatePicker;
import tmp.ac.lib.tools.util;

/**
 *
 * @author empcl_000
 */
public class utils extends updateitems {

    ;
        

    /// JDesktopPane jDesktopPane1;

 
    //<editor-fold defaultstate="collapsed" desc="Mssages">
    public static void sendMessage(Component parent, String title, String Message) {

        JOptionPane.showMessageDialog(parent, Message, title, JOptionPane.INFORMATION_MESSAGE);

        /*  MessageFrame f = new MessageFrame(Message);
         f.show();*/
    }

    public static void sendError(Component parent, String title, String Message) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        JOptionPane.showMessageDialog(parent, Message, op.getWord("title.error") + " " + title, JOptionPane.ERROR_MESSAGE);

        /*  MessageFrame f = new MessageFrame(Message);
         f.show();*/
    }

    public static int sendAlert(Component parent, String title, String Message) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        return JOptionPane.showConfirmDialog(parent, Message, op.getWord("title.alert") + " " + title, JOptionPane.WARNING_MESSAGE);

    }

    public static int sendConfirm(Component parent, String title, String Message) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        return JOptionPane.showConfirmDialog(parent, Message, op.getWord("title.confrim") + " " + title, JOptionPane.YES_NO_OPTION);

    }

    public static int sendDeleteMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();
        int d = sendConfirm(parent, op.getWord("title.delete"), op.getWord("message.delete"));
        return d;

    }

    public static int sendRemoveMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();
        int d = sendConfirm(parent, op.getWord("title.delete"), op.getWord("message.remove"));
        return d;

    }

    public static int sendRemoveAllMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();
        int d = sendConfirm(parent, op.getWord("title.delete"), op.getWord("message.removeAll"));
        return d;

    }

    public static int sendDeleteDoneMssage(Component parent, String moreString) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();
        int d = sendConfirm(parent, op.getWord("title.alert"), op.getWord("message.deleteDone") + moreString);
        return d;

    }
    
     public static int sendClearDBMssage(Component parent, String moreString) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();
        int d = sendConfirm(parent, op.getWord("title.alert"), op.getWord("message.sendClear") + moreString);
        return d;

    }
    
    

    public static void sendDeleteDoneMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.deleteDone"), op.getWord("message.deleteEnd"));

    }

    public static void sendDeleteErrorMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.saveError"), op.getWord("message.saveError"));

    }

    public static void sendMaxLimitErrorMssage(Component parent, String more) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.saveError"), op.getWord("message.MaxLimitError") + " " + more);

    }

    public static void sendMinLimitErrorMssage(Component parent, String more) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.saveError"), op.getWord("message.MinLimitError") + " " + more);

    }

    public static void sendRequiredNeedeMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, "", op.getWord("message.RequiredNeede"));

    }

    public static void sendSaveMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.save"), op.getWord("message.save"));

    }

    public static void sendSaveErrorMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.error"), op.getWord("message.saveError"));

    }

    public static void sendviewPermissionsErrorMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.error"), op.getWord("message.viewPermissionsError"));

    }

    public static void sendcanPermissionsErrorMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.error"), op.getWord("message.canPermissionsError"));

    }

    public static void sendLoginErrorMessage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.error"), op.getWord("message.LoginError"));

    }

    public static void sendUpdateMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.update"), op.getWord("message.update"));

    }

    public static void sendSatausMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.status"));

    }

    public static void sendCreateBillError(Component parent, String billnumber) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.CreateBillError") + " " + billnumber);

    }

    public static void sendCreateOrderError(Component parent, String billnumber) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.CreateOrderError") + " " + billnumber);

    }

    public static void sendPricMaxMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.pricmax"));

    }

    public static void sendClientbalanceError(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.ClientbalanceError"));

    }

    public static void sendPricMinMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendMessage(parent, op.getWord("title.error"), op.getWord("message.pricmin"));

    }

    public static void sendUpdateeErrorMssage(Component parent) {

        ac.uitls.propertiesOperation op = new ac.uitls.propertiesOperation();

        sendError(parent, op.getWord("title.error"), op.getWord("message.updateeError"));

    }

//</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Files">
    public static String getFolderPath(String Title) {

        String backUpPath = "";
        JFileChooser fc = null;
        if (fc == null) {
            fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setAcceptAllFileFilterUsed(false);
        }
        int returnVal = fc.showDialog(null, Title);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            backUpPath = file.getAbsolutePath();
        }
        return backUpPath;
    }

    public void saveImage(String chDirName, String chFileName) {
        /*     try {

         if (!chDirName.trim().equals("") && !chFileName.trim().equals("")) {
         URI url = this.getClass().getResource(urls.Image_URL).toURI();
         String myurl = url.toString().replace("file:/", "");
         tmp.ac.lib.tools.files.copyfile(chDirName, chFileName, myurl);
         }

         } catch (URISyntaxException ex) {
         Logger.getLogger(menuSetting.class.getName()).log(Level.SEVERE, null, ex);
         }
         */
    }
//</editor-fold>

    public String[] getDataFromComs(Component[] coms) {
        int i = 0;
        String[] r = new String[coms.length];
        for (Component c : coms) {

            if (c instanceof PCLCheckBox) {
                PCLCheckBox d = (PCLCheckBox) c;
                String o = "0";
                if (d.isSelected()) {
                    o = "1";
                }
                r[i] = o;
            } else if (c instanceof javax.swing.JButton) {
                javax.swing.JButton d = (javax.swing.JButton) c;
                r[i] = d.getText();
            } else if (c instanceof javax.swing.JLabel) {
                javax.swing.JLabel d = (javax.swing.JLabel) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLcomboboxAdd) {
                ac.ui.controls.PCLcomboboxAdd d = (ac.ui.controls.PCLcomboboxAdd) c;

                r[i] = custemItmes.comBoxGetValue(d);
            } else if (c instanceof ac.ui.controls.PCLTextField) {
                ac.ui.controls.PCLTextField d = (ac.ui.controls.PCLTextField) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLTextarea) {
                ac.ui.controls.PCLTextarea d = (ac.ui.controls.PCLTextarea) c;

                r[i] = d.getText();
            }
            i++;
        }
        return r;

    }

    public static String[] getDataFromComss(Component[] coms, String[] dataAs) {
        int i = 0;
        String[] r = new String[coms.length];

        for (Component c : coms) {

            if (c instanceof JXDatePicker) {
                JXDatePicker d = (JXDatePicker) c;

                // *** note that it's "yyyy-MM-dd hh:mm:ss" not "yyyy-mm-dd hh:mm:ss"  
                if (d.getDate() != null) {
                    SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");

                    String out = dt.format(d.getDate());

                    r[i] = out;
                }

            } else if (c instanceof ac.ui.controls.PCLImage) {
                ac.ui.controls.PCLImage d = (ac.ui.controls.PCLImage) c;

                r[i] = "" + d.getImageUrl();

            } else if (c instanceof javax.swing.JButton) {
                javax.swing.JButton d = (javax.swing.JButton) c;
                r[i] = d.getText();
            } else if (c instanceof PCLCode) {
                PCLCode d = (PCLCode) c;

                r[i] = d.getText();

            } else if (c instanceof PCLTree) {
                PCLTree d = (PCLTree) c;

                r[i] = d.getValue() ;

            } else if (c instanceof javax.swing.JLabel) {
                javax.swing.JLabel d = (javax.swing.JLabel) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLcomboBox) {
                ac.ui.controls.PCLcomboBox d = (ac.ui.controls.PCLcomboBox) c;

                if (dataAs.length > i) {
                    if (dataAs[i].equalsIgnoreCase("text")) {
                        r[i] = custemItmes.comBoxGetText(d);
                    } else {
                        r[i] = custemItmes.comBoxGetValue(d);
                    }
                } else {
                    r[i] = custemItmes.comBoxGetValue(d);
                }
            } else if (c instanceof ac.ui.controls.PCLGetdata) {

                ac.ui.controls.PCLGetdata d = (ac.ui.controls.PCLGetdata) c;

                if (dataAs.length > i) {
                    if (dataAs[i].equalsIgnoreCase("text")) {
                        r[i] = custemItmes.comBoxGetText(d);
                    } else {
                        r[i] = custemItmes.comBoxGetValue(d);
                    }
                } else {
                    r[i] = custemItmes.comBoxGetValue(d);
                }

            } else if (c instanceof ac.ui.controls.PCLcomboboxAdd) {
                ac.ui.controls.PCLcomboboxAdd d = (ac.ui.controls.PCLcomboboxAdd) c;

                if (dataAs.length > i) {
                    if (dataAs[i].equalsIgnoreCase("text")) {
                        r[i] = custemItmes.comBoxGetText(d);
                    } else {
                        r[i] = custemItmes.comBoxGetValue(d);
                    }
                } else {
                    r[i] = custemItmes.comBoxGetValue(d);
                }
            } else if (c instanceof ac.ui.controls.PCLTextField) {
                ac.ui.controls.PCLTextField d = (ac.ui.controls.PCLTextField) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLTextarea) {
                ac.ui.controls.PCLTextarea d = (ac.ui.controls.PCLTextarea) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLSpinner) {
                ac.ui.controls.PCLSpinner d = (ac.ui.controls.PCLSpinner) c;

                r[i] = "" + d.getValue();
            } else if (c instanceof ac.ui.controls.PCLMoney) {
                ac.ui.controls.PCLMoney d = (ac.ui.controls.PCLMoney) c;

                r[i] = "" + d.getValue();
            }
            i++;
        }
        return r;

    }

    public static String[] getDataFromComss(Component[] coms) {
        int i = 0;
        String[] r = new String[coms.length];

        for (Component c : coms) {

            if (c instanceof JXDatePicker) {
                JXDatePicker d = (JXDatePicker) c;

                // *** note that it's "yyyy-MM-dd hh:mm:ss" not "yyyy-mm-dd hh:mm:ss"  
                if (d.getDate() != null) {
                    SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");

                    String out = dt.format(d.getDate());

                    r[i] = out;
                }

            } else if (c instanceof ac.ui.controls.PCLPasswordField) {

                ac.ui.controls.PCLPasswordField d = (ac.ui.controls.PCLPasswordField) c;

                String s = new String(d.getPassword());

                r[i] = "" + util.md5(s);

            } else if (c instanceof ac.ui.controls.PCLList) {

                ac.ui.controls.PCLList d = (ac.ui.controls.PCLList) c;

                r[i] = "" + d.getValue();

            } else if (c instanceof ac.ui.controls.PCLImage) {
                ac.ui.controls.PCLImage d = (ac.ui.controls.PCLImage) c;

                r[i] = "" + d.getImageUrl();

            } else if (c instanceof javax.swing.JButton) {
                javax.swing.JButton d = (javax.swing.JButton) c;
                r[i] = d.getText();
            } else if (c instanceof PCLCode) {
                PCLCode d = (PCLCode) c;

                r[i] = d.getText();

            } else if (c instanceof PCLTree) {
                PCLTree d = (PCLTree) c;

                r[i] =d.getValue() ;

            } else if (c instanceof javax.swing.JLabel) {
                javax.swing.JLabel d = (javax.swing.JLabel) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLcomboBox) {
                ac.ui.controls.PCLcomboBox d = (ac.ui.controls.PCLcomboBox) c;

                r[i] = custemItmes.comBoxGetValue(d);
            } else if (c instanceof ac.ui.controls.PCLGetdata) {
                ac.ui.controls.PCLGetdata d = (ac.ui.controls.PCLGetdata) c;

                r[i] = custemItmes.comBoxGetValue(d);
            } else if (c instanceof ac.ui.controls.PCLcomboboxAdd) {
                ac.ui.controls.PCLcomboboxAdd d = (ac.ui.controls.PCLcomboboxAdd) c;

                r[i] = custemItmes.comBoxGetValue(d);
            } else if (c instanceof ac.ui.controls.PCLTextField) {
                ac.ui.controls.PCLTextField d = (ac.ui.controls.PCLTextField) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLTextarea) {
                ac.ui.controls.PCLTextarea d = (ac.ui.controls.PCLTextarea) c;

                r[i] = d.getText();
            } else if (c instanceof ac.ui.controls.PCLSpinner) {
                ac.ui.controls.PCLSpinner d = (ac.ui.controls.PCLSpinner) c;

                r[i] = "" + d.getValue();
            } else if (c instanceof ac.ui.controls.PCLMoney) {
                ac.ui.controls.PCLMoney d = (ac.ui.controls.PCLMoney) c;

                r[i] = "" + d.getValue();
            }
            i++;
        }
        return r;

    }

    public void SetjToolBar(JToolBar jtoolbar) {

        this.jToolBar2 = jtoolbar;

    }

    public static void openWindows(JFrame f, int Width, int height) {

        f.setVisible(true);
        f.show();

    }

    public static void openTool(String title, PCLPanel p) {
        ac.GUI.engin.viewTool f = new ac.GUI.engin.viewTool(title, p);
        f.setVisible(true);

    }

    public void closeWindows() {
        //    primaryStage.close();
    }

    public void EndPrograme() {
    }

    public void createColorFiled(final JTextField tf) {
        // ColorChooser c = new ColorChooser(tf);
        /*   if (op.getProperty("lang").equals("ar")) {

         c.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
         }*/
        //    c.show();
    }

    /*public void SetjDesktopPane(JDesktopPane jDesktopPane1) {
        
     this.jDesktopPane1 = jDesktopPane1;
        
     }*/
    // propertiesOperation op =new propertiesOperation();
    /*
     public void openMidWindows(final JInternalFrame f, String title) throws IOException {

     JButton button2 = new JButton("X");
     final JToolBar p = new JToolBar();

     // BasicInternalFrameTitlePane titlePane =(BasicInternalFrameTitlePane) ((BasicInternalFrameUI) f.getUI()).getNorthPane();
     // f.remove(titlePane);
     button2.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {

     jToolBar2.remove(p);
     jToolBar2.revalidate();
     jToolBar2.repaint();
     jDesktopPane1.remove(f);
     jDesktopPane1.repaint();

     }
     });

     JLabel l = new JLabel(" " + (op.getWord("label." + title)) + " ");
     //    p.setFloatable(false);
     p.add(l);

     p.addMouseListener(new java.awt.event.MouseAdapter() {
     public void mouseClicked(java.awt.event.MouseEvent evt) {
     for (int i = 0; i < jToolBar2.getComponentCount(); i++) {
     JToolBar mp = (JToolBar) jToolBar2.getComponent(i);
     mp.setBorder(BorderFactory.createLineBorder(Color.GRAY));
     }
     p.setBorder(BorderFactory.createLineBorder(Color.BLUE));

     jDesktopPane1.setSelectedFrame(f);
     f.toFront();

     jDesktopPane1.repaint();

     }
     });

     p.add(button2);

     p.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
     p.setBorder(BorderFactory.createLineBorder(Color.GRAY));

     jToolBar2.add(p);

     jDesktopPane1.add(f);
     f.setMaximizable(true);
     try {
     f.setMaximum(true);
     } catch (PropertyVetoException ex) {
     Logger.getLogger(mian.class.getName()).log(Level.SEVERE, null, ex);
     }
     if (op.getProperty("lang").equalsIgnoreCase("ar")) {

     f.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
     }

     f.setVisible(true);
     }*/
}
